//
//  UIViewController+PageViewController.m
//  ZSComponent
//
//  Created by HuangZuShu on 17/9/8.
//  Copyright © 2017年 Mac. All rights reserved.
//

#import "UIViewController+ZSPageViewController.h"
#import <objc/runtime.h>

static NSString * kPageBarView = @"kPageBarView";
static NSString * kPageScrollView = @"kPageScrollView";

@implementation UIViewController (ZSPageViewController)



- (void)initializePageViewControllerWithNormalColor:(UIColor *)normalColor normalFont:(UIFont *)normalFont selectedColor:(UIColor *)selectedColor selectedFont:(UIFont *)selectedFont itemTitles:(NSArray *)itemTitles cellSize:(CGSize)cellSize {
    
    ZSPageBarView * pageBarView = [[ZSPageBarView alloc] initNormalColor:normalColor normalFont:normalFont selectedColor:selectedColor selectedFont:selectedFont itemTitles:itemTitles cellSize:cellSize];
    pageBarView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:pageBarView];
    [pageBarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.top.equalTo(self.view);
        make.right.equalTo(self.view);
        make.height.equalTo(@(cellSize.height));
    }];
    self.pageBarView = pageBarView;
    
    UIScrollView * pageScrollView = [[UIScrollView alloc] init];
    pageScrollView.backgroundColor = [UIColor greenColor];
    pageScrollView.pagingEnabled = YES;
    pageScrollView.delegate = self;
    pageScrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * 5, [UIScreen mainScreen].bounds.size.height - 64 - cellSize.height);
    [self.view addSubview:pageScrollView];
    self.pageScrollView = pageScrollView;
    [self.pageScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.top.equalTo(self.pageBarView.mas_bottom);
        make.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
    }];
    
}






- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
}



- (void)setPageBarView:(ZSPageBarView *)pageBarView {
    objc_setAssociatedObject(self, &kPageBarView, pageBarView,OBJC_ASSOCIATION_ASSIGN);
}
- (ZSPageBarView *)pageBarView {
    return objc_getAssociatedObject(self, &kPageBarView);
}


- (void)setPageScrollView:(UIScrollView *)pageScrollView {
    objc_setAssociatedObject(self, &kPageScrollView, pageScrollView,OBJC_ASSOCIATION_ASSIGN);
}
- (UIScrollView *)pageScrollView {
    return objc_getAssociatedObject(self, &kPageScrollView);
}




@end
